home *** CD-ROM | disk | FTP | other *** search
- /*
- File: DragUtils.cp
-
- Contains: Useful utility functions when using the Drag Manager.
-
- Written by: Dave Falkenburg and Cameron Esfahani
-
- Copyright: Copyright © 1993-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 7/27/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
- 11/12/94 DRF Added #include to pick up function prototype.
-
- */
- #include "Sprocket.h"
-
- #include <Folders.h>
-
- Boolean
- DragDestinationIsTheTrash(DragReference theDrag)
- {
- AEDesc dropLocation;
- AEDesc dropFSSpecDesc;
- Boolean wasItDraggedToTrash = false;
- OSErr err;
-
- err = GetDropLocation(theDrag, &dropLocation);
- if (err != noErr)
- return false;
-
- if ((dropLocation.descriptorType != typeNull) &&
- (AECoerceDesc(&dropLocation, typeFSS, &dropFSSpecDesc) == noErr))
- {
- FSSpec * theDropFSSpec;
- CInfoPBRec theCatInfoPB;
- long trashDirID;
- short trashVRefNum;
-
- // If we got here, the drag went to a file system thing
-
- HLock(dropFSSpecDesc.dataHandle);
- theDropFSSpec = (FSSpec *) *dropFSSpecDesc.dataHandle;
-
- theCatInfoPB.dirInfo.ioCompletion = nil;
- theCatInfoPB.dirInfo.ioNamePtr = (StringPtr) &theDropFSSpec->name;
- theCatInfoPB.dirInfo.ioVRefNum = theDropFSSpec->vRefNum;
- theCatInfoPB.dirInfo.ioFDirIndex = 0;
- theCatInfoPB.dirInfo.ioDrDirID = theDropFSSpec->parID;
- if (PBGetCatInfoSync(&theCatInfoPB) != noErr)
- goto bail;
-
- // Is it a directory?
-
- if (!(theCatInfoPB.dirInfo.ioFlAttrib & ioDirMask))
- goto bail;
-
- // Is it the trash folder?
-
- (void) FindFolder(kOnSystemDisk,kTrashFolderType,kCreateFolder,&trashVRefNum,&trashDirID);
-
- if ((theDropFSSpec->vRefNum == trashVRefNum) && (theCatInfoPB.dirInfo.ioDrDirID == trashDirID))
- wasItDraggedToTrash = true;
- }
-
- bail:
- HUnlock(dropFSSpecDesc.dataHandle);
- AEDisposeDesc(&dropFSSpecDesc);
- AEDisposeDesc(&dropLocation);
-
- return wasItDraggedToTrash;
- }
-